package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EsUser;
import com.ruoyi.system.service.IEsUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房产用户信息Controller
 * 
 * @author ruoyi
 * @date 2022-05-26
 */
@Controller
@RequestMapping("/es/user")
public class EsUserController extends BaseController
{
    private String prefix = "es/user";

    @Autowired
    private IEsUserService esUserService;

    @RequiresPermissions("es:user:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }

    /**
     * 查询房产用户信息列表
     */
    @RequiresPermissions("es:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EsUser esUser)
    {
        startPage();
        List<EsUser> list = esUserService.selectEsUserList(esUser);
        return getDataTable(list);
    }

    /**
     * 导出房产用户信息列表
     */
    @RequiresPermissions("es:user:export")
    @Log(title = "房产用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EsUser esUser)
    {
        List<EsUser> list = esUserService.selectEsUserList(esUser);
        ExcelUtil<EsUser> util = new ExcelUtil<EsUser>(EsUser.class);
        return util.exportExcel(list, "房产用户信息数据");
    }

    /**
     * 新增房产用户信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存房产用户信息
     */
    @RequiresPermissions("es:user:add")
    @Log(title = "房产用户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EsUser esUser)
    {
        return toAjax(esUserService.insertEsUser(esUser));
    }

    /**
     * 修改房产用户信息
     */
    @RequiresPermissions("es:user:edit")
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        EsUser esUser = esUserService.selectEsUserByUserId(userId);
        mmap.put("esUser", esUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存房产用户信息
     */
    @RequiresPermissions("es:user:edit")
    @Log(title = "房产用户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EsUser esUser)
    {
        return toAjax(esUserService.updateEsUser(esUser));
    }

    /**
     * 删除房产用户信息
     */
    @RequiresPermissions("es:user:remove")
    @Log(title = "房产用户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(esUserService.deleteEsUserByUserIds(ids));
    }
}
